﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyWeb.Business;
using MyWeb.Common;
using System.Data;
namespace MyWeb.Control.Home
{
    public partial class ColRight : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadCard();
                lsvhotro.DataSource = SurportService.Surport_GetByAll();
                lsvhotro.DataBind();
                lsvquangcao.DataSource = AdvertiseService.Advertise_GetByPosition("3");
                lsvquangcao.DataBind();
                lsvtinmoi.DataSource = NewsService.News_GetByTop("6", "", "Id desc");
                lsvtinmoi.DataBind();
            }
        }
        protected string Url(string GrId, string Id, string Name)
        {
            return "/News/" + GrId + "/" + Id + "/" + StringClass.NameToTag(Name) + ".aspx";
        }
        protected string Formatmoney(string money)
        {
            string tien = "";
            try
            {
                tien = "" + Double.Parse(money).ToString("#,000") + " VNĐ";
            }
            catch
            {
                return tien = "";
            }
            return tien;
        }
        protected void LoadCard()
        {
            int num = 0;
            if (Session["Cart"] != null)
            {
                DataTable dt = (DataTable)Session["Cart"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        num += int.Parse(dt.Rows[i]["TotalPrice"].ToString());
                    }
                }
                lblsoluong.Text = "Tổng cộng: " +Formatmoney(num.ToString()) + " ";
            }
            else
            {
                lblsoluong.Text = "Tổng cộng: 0 VNĐ";
            }
        }
    }
}